const express = require('express');
const router = express.Router();
const {asyncHandler} = require('../utils/sendResult');
const {
    addEnterprise,
    editEnterprise,
    deleteEnterpriseOne,
    getEnterpriseByPage,
    editEnterpriseStatus,
    getEnterpriseByUser
} = require("../services/enterpriseServices");

// 分页获取企业列表
router.get("/", asyncHandler((req, res, next) => {
    return getEnterpriseByPage(req.query)
}))

// 添加企业待审核
router.post("/", asyncHandler((req, res, next) => {
    req.body.user = req.userInfo._id;
    req.body.status = 0;
    return addEnterprise(req.body)
}))

// 更新企业
router.post("/:id", asyncHandler((req, res, next) => {
    return editEnterprise(req.params.id, req.body)
}))

// 修改企业状态
router.post("/status/:id", asyncHandler((req, res, next) => {
    return editEnterpriseStatus(req.params.id, req.body.status)
}))


// 通过用户获取该企业
router.get("/byUser/:userId", asyncHandler((req, res, next) => {
    return getEnterpriseByUser(req.params.userId)
}))

// 删除企业
router.delete("/:id", asyncHandler((req, res, next) => {
    return deleteEnterpriseOne(req.params.id)
}))


module.exports = router;
